import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import disruptor.LongEvent;
import disruptor.PreferLambdaMain;
import event.EventObject;
import handler.UserHandlerEvent;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import publish.EventPublisher;

import java.nio.ByteBuffer;

/**
 * Created by dongjigong on 2018/5/25.
 *
 * @Email osbornjonny@126.com
 * @Description
 */
public class Main {

    public static void main(String[] args) throws InterruptedException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-beans.xml");

        context.registerShutdownHook();

        Disruptor<EventObject> disruptor = (Disruptor) context.getBean("disruptor");

        disruptor.handleEventsWith(new UserHandlerEvent());

        disruptor.start();

        RingBuffer<EventObject> ringBuffer = disruptor.getRingBuffer();

        ByteBuffer bb = ByteBuffer.allocate(8);
        for (long l = 0; true; l++) {
            bb.putLong(0, l);
            ringBuffer.publishEvent(new EventPublisher<>());
            Thread.sleep(1000);
        }
    }
}
